///////////////////////////////////////////////////////////////////////////////
//! @file	: image_scaling.cl
//! @date   : 2016/03/04
//! @author: guyadong
//! @brief  : zoom an image
////////////////////////////////////////////////////////////////////////////////
#include "common_types.h"

__constant sampler_t sampler = CLK_NORMALIZED_COORDS_TRUE | CLK_ADDRESS_CLAMP | CLK_FILTER_LINEAR;
__kernel void image_scaling(__read_only image2d_t sourceImage
                            ,__write_only image2d_t destinationImage
                            ,const float2 normalization_factor){
	const int dest_width	= get_image_width( destinationImage );
	const int dest_height	= get_image_height( destinationImage );
	const int v_step	= gf_get_divisor(dest_height,get_global_size(0));
	
	int2 pos=(int2)(0,get_global_id(0)*v_step);		
	float2 norm_pos;
	for(int end_y=min(dest_height,pos.y+v_step);pos.y<end_y;++pos.y){
		for(pos.x=0,norm_pos = convert_float2(pos) * normalization_factor
			;pos.x<dest_width
			;norm_pos.x = (++pos.x) * normalization_factor.x){
			write_imagef(destinationImage, pos, read_imagef(sourceImage, sampler, norm_pos));
		}
	}
}